package com.cuijq.virwallet.controller;

import com.cuijq.virwallet.exception.NoSufficientBalanceException;
import com.cuijq.virwallet.service.VirtualWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
@RestController
public class VirtualWalletController {
    // 通过构造函数或者IOC框架注入
    @Autowired
    private VirtualWalletService virtualWalletService;

    public BigDecimal getBalance(Long walletId) {
       return virtualWalletService.getBalance(walletId);
    }//查询余额

    public void debit(Long walletId, BigDecimal amount) throws NoSufficientBalanceException {
         virtualWalletService.debit(walletId,amount);
    } //出账

    public void credit(Long walletId, BigDecimal amount) {
        virtualWalletService.credit(walletId,amount);
    }
    //入账
    public void transfer(Long fromWalletId, Long toWalletId, BigDecimal amount) {
        virtualWalletService.transfer(fromWalletId,toWalletId,amount);
    } //转账
}
